package com.tianji.learning.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.tianji.api.dto.IdAndNumDTO;
import com.tianji.learning.domain.po.LearningRecord;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 学习记录表 Mapper 接口
 * </p>
 *
 * @author xiaohai
 * @since 2024-09-12
 */
public interface LearningRecordMapper extends BaseMapper<LearningRecord> {

    /**
     * 查询本周已学习章节数
     *
     * @param userId
     * @param weekBeginTime
     * @param weekEndTime
     * @return
     */
    @Select("select lesson_id id,count(*) num from learning_record where user_id = #{userId} and finished = 1 and finish_time > #{weekBeginTime} and finish_time < #{weekEndTime} group by lesson_id;")
    List<IdAndNumDTO> countLearnedSections(
            @Param("userId") Long userId,
            @Param("weekBeginTime") LocalDateTime weekBeginTime,
            @Param("weekEndTime") LocalDateTime weekEndTime);
}
